import requests
import re
from urllib3.exceptions import InsecureRequestWarning
import datetime

today = datetime.date.today()  # 今天
yester = today - datetime.timedelta(days=1)
# 禁用安全请求警告

Platform = "阅微"


def yuewei():
    try:
        requests.urllib3.disable_warnings(InsecureRequestWarning)
        r = requests.session()
        url = "http://novel.ywread.net/admin.php/user/publics/signin.html"
        data = {
            "username": "",
            "password": ""
        }
        rr = r.post(url=url, data=data, verify=False, timeout=15)
        aa = r.get(url="http://novel.ywread.net/admin.php/agent/statistical/paylog.html", verify=False, timeout=15)
        html = aa.text.replace('\r', '').replace('\t', '').replace('\n', '')
        date_time = str(yester)
        Amount_share_list = re.findall('<td class="">\s+(\d?,?\d+\.\d+)\s+</td>', html)
        Amount_share = round(float(Amount_share_list[1]) * 0.91, 2)
        return date_time, Amount_share, Platform
    except Exception:
        print("获取 阅微 数据失败")
        return '', 'None', Platform
    except ConnectionError:
        print("获取 阅微 数据 超时")
        return '', 'None', Platform